<template>
  <span
    :title="title"
    :style="[
      { fontSize: fontSize ? fontSize + 'px' : '' },
      { color: color ? color : '' }
    ]"
  >
    <svg class="svg-icon" aria-hidden="true">
      <use :xlink:href="iconName"></use>
    </svg>
  </span>
</template>

<script>
import { reactive, toRefs, computed } from "vue";
export default {
  name: "icon",
  props: ["title", "icon", "fontSize", "color"],
  setup(props) {
    const _this = reactive({
      iconName: computed(() => {
        return `#icon-${props.icon}`;
      })
    });

    return {
      ...toRefs(_this)
    };
  }
};
</script>

<style lang="scss" scoped>
span {
  font-size: 16px;
  transition: color 0.3s;
  display: flex;
  align-items: center;
}
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
  cursor: pointer;
}
</style>
